<?php
/**
 * Created by PhpStorm.
 * User: Dell
 * Date: 2019-3-7
 * Time: 10:56
 */

namespace app\index\controller;


use app\common\model\MemberModel;
use think\Session;

class Member extends Base
{
    protected function getUname(){
        $phone = Session::get('phone');
        $name = Session::get('name');
        $uname = empty($name)?$phone:$name;
        if (!empty($uname)){
            $this->assign([
                'uname'=>$uname
            ]);
        }
    }

    //会员编辑
    public function memberEdit(){
        if (request()->isAjax()){
            $param = input("param.");
            $id = Session::get('id');
            $member = new MemberModel();

            $user = $member->getOneMember($id);
            $param['memb_id'] = $user['memb_id'];
            unset($param['memb_password']);//拒绝修改密码
            unset($param['memb_phone']);//拒绝修改手机号

            $flag = $member->editMember($param);

            return json(msg($flag['code'], $flag['data'], $flag['msg']));
        }
    }

    //修改默认收件地址
    public function editAddress(){
        if (request()->isAjax()){
            $param = input("param.");
            $id = Session::get('id');
            $member = new MemberModel();
            $param['memb_id'] = $id;
            unset($param['memb_password']);

            $flag = $member->editMemberAddress($param);

            return json(msg($flag['code'], $flag['data'], $flag['msg']));
        }
    }

    //获取单个用户信息
    public function getOneMember(){
        if (request()->isAjax()){
            $member = new MemberModel();
            $id = Session::get('id');
            $field = "memb_name,memb_sex,memb_birthday,memb_dwell,memb_phone";
            $rows = $member->getOneMember($id,$field);
            return json(msg(1, '', $rows));
        }
    }

    //获取单个用户寄货地址
    public function getMemberAddress(){
        if (request()->isAjax()){
            $member = new MemberModel();
            $id = Session::get('id');
            $field = "memb_addrPhone,memb_addrName,memb_city,memb_address";
            $rows = $member->getOneMember($id,$field);
            return json(msg(1, '', $rows));

        }
    }

    //修改用户页面
    public function user_info_edit()
    {
        $this->getUname();
        return $this->fetch();
    }


}